﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using ScrumTable.DL.Data.Generic.Properties;

#endregion


namespace ScrumTable.DL.Data.Generic.Cache
{
    /// <summary>
    /// Represents an error which is used in conjunction with a TFS
    /// call or callback. So you can pass a set of arguments to the
    /// constructor which will be written into the output exception
    /// message.
    /// </summary>
    public class CacheException : ApplicationException
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private const string ErrorArgSeparator = ", ";

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new CacheException instance.
        /// </summary>
        internal CacheException(Exception inner, string command, params object[] arguments)
            : base(GetErrorMessage(command, arguments), inner)
        {
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        private static string GetErrorMessage(string command, object[] arguments)
        {
            return string.Format(Resources.ExcCacheError, command, FromArguments(arguments));
        }

        private static string FromArguments(object[] argumentsRaw)
        {
            return string.Join(
                ErrorArgSeparator,
                Array.ConvertAll(argumentsRaw, input => input.ToString()));
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}
